﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using EITSurferInfinityLib;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for WHostParameter.xaml
    /// </summary>
    public partial class WHostParameter : Window
    {
        public object ctrl ;
        string MyType;
        VirtualDevice Device;

        public WHostParameter(ref VirtualDevice device, string type)
        {
            InitializeComponent();
            Device = device;
            switch (type)
            {
                case "settings":
                    string[] revisions = device.DeviceName.Split('_');
                    SelectSettingGUI(revisions[2],ref device);
                    MyType = type;
                    break;
                case "protocol":
                    ctrl = new ControlerLib.ProtocolControler(ref device);
                    grid.Children.Add((ControlerLib.ProtocolControler)ctrl);
                    MyType = type;
                    break;
            }
        }

        private void SelectSettingGUI(string s, ref VirtualDevice device)
        {
            switch (s)
            {
                case "0.12":
                    ctrl = new Settings_st_1_0p12(ref device);
                    break;
                case "0.111":
                    ctrl = new Settings_st_1_0p111(ref device);
                    break;
            }
            grid.Children.Add((UserControl)ctrl);
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            System.Windows.Controls.UserControl temp= (System.Windows.Controls.UserControl)ctrl;
            if (MyType == "protocol")
            {
                this.Width = 750;
                this.Height = 350;
            }
            else
            {
                this.SizeToContent = SizeToContent.WidthAndHeight;
            }
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Device.Busy = false;
            Device.BusyFrame = false;
            Device.Saving = false;
            Device.BusySerial = false;
        }
    }
}
